clear
infile int ccode1 int ccode2 int year long xrcomp1 long xrcomp2 long xropen1 long xropen2 long xconst1 long xconst2 long parcomp1 long parcomp2  using "D:\REPLY TO DR\Werner Pol Sim.out"

* The next command drops the case that was read 
*  if the user included a line of variable names

drop if missing(ccode1) | missing(year)

* Interpret missing values 
mvdecode ccode1 ccode2 year , mv(-9)
mvdecode xrcomp1, mv(-99)
mvdecode xrcomp2, mv(-99)
mvdecode xropen1, mv(-99)
mvdecode xropen2, mv(-99)
mvdecode xconst1, mv(-99)
mvdecode xconst2, mv(-99)
mvdecode parcomp1, mv(-99)
mvdecode parcomp2, mv(-99)

* Variable labels where available (see EUGeneDocumentation.doc for full information) 
label variable ccode1 "COW CCode Num for state 1"
label variable ccode2 "COW CCode Num for state 2"
label variable year "Year of observation"

compress
gen dyadid=(10000*ccode1)+ccode2
sort dyadid

foreach v in xrcomp1 xrcomp2 xropen1 xropen2 xconst1 xconst2 parcomp1 parcomp2  {
gen n`v'=`v'
mvdecode n`v', mv(-88)
mvdecode n`v', mv(-77)
mvdecode n`v', mv(-66)
by dyadid: ipolate n`v' year, gen(ip`v')
replace ip`v'=. if `v'==-77 | `v'==-66 | `v'==.
drop n`v'
}
gen PolDistrans=sqrt((((ipxrcomp1-ipxrcomp2)/3)^2)+(((ipxropen1-ipxropen2)/4)^2)+(((ipxconst1-ipxconst2)/6)^2)+(((ipparcomp1-ipparcomp2)/5)^2))
label var PolDistrans "We account only for -88"
*The imputations made in this variable are analogus to creation of Polity2, except we dont impute -77.

*xrcomp 1.5, nxropen 2, nxconst 4, nparcomp 2.5
foreach v in xrcomp1 xrcomp2 xropen1 xropen2 xconst1 xconst2 parcomp1 parcomp2  {
gen n`v'=`v'
mvdecode n`v', mv(-88)
mvdecode n`v', mv(-66)
}
replace nxrcomp1=1.5 if nxrcomp1==-77
replace nxrcomp2=1.5 if nxrcomp2==-77
replace nxropen1=2 if nxropen1==-77
replace nxropen2=2 if nxropen2==-77
replace nxconst1=4 if nxconst1==-77
replace nxconst2=4 if nxconst2==-77
replace nparcomp1=2.5 if nparcomp1==-77
replace nparcomp2=2.5 if nparcomp2==-77
foreach v in xrcomp1 xrcomp2 xropen1 xropen2 xconst1 xconst2 parcomp1 parcomp2  {


by dyadid: ipolate n`v' year, gen(full`v')
replace full`v'=. if `v'==-66 | `v'==.
drop n`v'
}
gen PolDisfull=sqrt((((fullxrcomp1-fullxrcomp2)/3)^2)+(((fullxropen1-fullxropen2)/4)^2)+(((fullxconst1-fullxconst2)/6)^2)+(((fullparcomp1-fullparcomp2)/5)^2))
label var PolDisfull "We account for -88 & -77"
*The imputations made in this variable are analogus to creation of Polity2.
 foreach v in xrcomp1 xrcomp2 xropen1 xropen2 xconst1 xconst2 parcomp1 parcomp2  {
 mvdecode `v', mv(-88)
 mvdecode `v', mv(-77)
 mvdecode `v', mv(-66)
 }

gen PolDis=sqrt((((xrcomp1-xrcomp2)/3)^2)+(((xropen1-xropen2)/4)^2)+(((xconst1-xconst2)/6)^2)+(((parcomp1-parcomp2)/5)^2))
label var PolDis "Political Dissimilarity"
*No imputations made in the creation of this variable.

foreach v in xrcomp1 xrcomp2 xropen1 xropen2 xconst1 xconst2 parcomp1 parcomp2  {
drop `v' full`v' ip`v'
}
save "D:\REPLY TO DR\Political Dissimilarity Werner.dta", replace

clear
use "D:\REPLY TO DR\MOUM2012.dta"
joinby ccode1 ccode2 dyadid year using "D:\REPLY TO DR\Political Dissimilarity Werner.dta", unmatched (both)
tab _merge
drop _merge
save "D:\REPLY TO DR\MOUM Reply 2012", replace


clear
use "D:\REPLY TO DR\MOUM Reply 2012"

**********************************************************************************
******************TABLE 2: CIE, DEMOCRACY AND ICB ONSET, 1960-2001****************
**********************************************************************************

quietly {
global controlvars  lncprt  majpow cntgd dist  numstate  peaceyrs _spline1 _spline2 _spline3
eststo clear
*Table 1, Model 1
eststo: logit 		crisis1 	   		  dml   PolDis 			  $controlvars if CIEl!=., cl(dyadid) nolog
*Table 1, Model 2
eststo: logit 		crisis1 		CIEl  dml   PolDis 			  $controlvars, cl(dyadid) nolog
*Table 1, Model 3
eststo: logit 		crisis1 		CIEl  bdm   PolDis 			  $controlvars, cl(dyadid) nolog
*Table 1, Model 4
eststo: logit 		crisis1 		CIEl  dm10  PolDis 		  $controlvars, cl(dyadid) nolog
*Table 1, Model 5
eststo: logit 		crisis1         CIEl  dmlsq	 PolDis  		  $controlvars, cl(dyadid) nolog
*Table 1, Model 6
eststo: logit 		crisis1 		CIEl  	                      $controlvars, cl(dyadid) nolog
}
esttab, b(2) se(2) replace label star(* 0.10 ** 0.05 *** 0.01)  order(CIEl dml bdm dmlsq PolDis $controlvars) scalars("ll Log lik.") pr2 varwidth(25) modelwidth(8)
esttab using Poldis1.rtf, b(a2) se(2) replace label star(* 0.10 ** 0.05 *** 0.01) scalars("ll Log lik." "chi2 Chi-squared") pr2  varwidth(25) modelwidth(6)       ///
title(Table 1. CIE, Democracy and ICB Crisis Onset, 1961-2001)       ///
nonumbers mtitles("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6")  ///
order(CIEl dml bdm dmlsq PolDis $controlvars) ///
addnote("") ///
nogap


**********************************************************************************
*TABLE 3: SIGNIFICANCE OF DIFFERENCE AND DECOMPOSITION OF THE DEMOCRACY VARIABLES*
**********************************************************************************
global controlvars   lncprt  majpow cntgd dist  numstate  peaceyrs _spline1 _spline2 _spline3

khb logit 		crisis1 		 dml   || CIEl , vce(cl dyadid)  summary  concomitant($controlvars  dmdist) 
khb logit 		crisis1 		 bdm   || CIEl , vce(cl dyadid)  summary  concomitant($controlvars  dmdist) 
khb logit       crisis1         dmlsq  || CIEl , vce(cl dyadid)  summary   concomitant($controlvars  dmdist)


**********************************************************************************
******************TABLE A1: CIE, DEMOCRACY AND ICB ONSET, 1960-2001****************
**********************************************************************************
quietly {
global controlvars  lncprt  majpow cntgd dist  numstate  peaceyrs _spline1 _spline2 _spline3
eststo clear
*Table 1, Model 1
eststo: logit 		crisis1 	   		  dml   PolDistrans 			  $controlvars if CIEl!=., cl(dyadid) nolog
*Table 1, Model 2
eststo: logit 		crisis1 		CIEl  dml   PolDistrans 			  $controlvars, cl(dyadid) nolog
*Table 1, Model 3
eststo: logit 		crisis1 		CIEl  bdm   PolDistrans 			  $controlvars, cl(dyadid) nolog
*Table 1, Model 4
eststo: logit 		crisis1 		CIEl  dm10  PolDistrans 		  $controlvars, cl(dyadid) nolog
*Table 1, Model 5
eststo: logit 		crisis1         CIEl  dmlsq	PolDistrans 		  $controlvars, cl(dyadid) nolog
*Table 1, Model 6
eststo: logit 		crisis1 		CIEl  	                      $controlvars, cl(dyadid) nolog
}
esttab, b(2) se(2) replace label star(* 0.10 ** 0.05 *** 0.01)  order(CIEl dml bdm dmlsq PolDistrans $controlvars) scalars("ll Log lik.") pr2 varwidth(25) modelwidth(8)
esttab using Poldis2.rtf, b(a2) se(2) replace label star(* 0.10 ** 0.05 *** 0.01) scalars("ll Log lik." "chi2 Chi-squared") pr2  varwidth(25) modelwidth(6)       ///
title(Table 1. CIE, Democracy and ICB Crisis Onset, 1961-2001)       ///
nonumbers mtitles("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6")  ///
order(CIEl dml bdm dmlsq PolDistrans $controlvars) ///
addnote("") ///
nogap

**********************************************************************************
******************TABLE A2: CIE, DEMOCRACY AND ICB ONSET, 1960-2001***************
**********************************************************************************

quietly {
global controlvars  lncprt  majpow cntgd dist  numstate  peaceyrs _spline1 _spline2 _spline3
eststo clear
*Table 1, Model 1
eststo: logit 		crisis1 	   		  dml   PolDisfull 			  $controlvars if CIEl!=., cl(dyadid) nolog
*Table 1, Model 2
eststo: logit 		crisis1 		CIEl  dml   PolDisfull 			  $controlvars, cl(dyadid) nolog
*Table 1, Model 3
eststo: logit 		crisis1 		CIEl  bdm   PolDisfull 			  $controlvars, cl(dyadid) nolog
*Table 1, Model 4
eststo: logit 		crisis1 		CIEl  dm10  PolDisfull 		  $controlvars, cl(dyadid) nolog
*Table 1, Model 5
eststo: logit 		crisis1         CIEl  dmlsq	 PolDisfull  		  $controlvars, cl(dyadid) nolog
*Table 1, Model 6
eststo: logit 		crisis1 		CIEl  	                      $controlvars, cl(dyadid) nolog
}
esttab, b(2) se(2) replace label star(* 0.10 ** 0.05 *** 0.01)  order(CIEl dml bdm dmlsq PolDisfull $controlvars) scalars("ll Log lik.") pr2 varwidth(25) modelwidth(8)
esttab using Poldis3.rtf, b(a2) se(2) replace label star(* 0.10 ** 0.05 *** 0.01) scalars("ll Log lik." "chi2 Chi-squared") pr2  varwidth(25) modelwidth(6)       ///
title(Table 1. CIE, Democracy and ICB Crisis Onset, 1961-2001)       ///
nonumbers mtitles("Model 1" "Model 2" "Model 3" "Model 4" "Model 5" "Model 6")  ///
order(CIEl dml bdm dmlsq PolDisfull $controlvars) ///
addnote("") ///
nogap
